<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>留言板</title>
    <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<?php
// 连接数据库
$db = mysqli_connect("localhost", "root", "", "guestbook");
// 读取留言信息
if ($db) {
    if (isset($_POST["name"])) {
        $ne = $_POST["name"];
        $em = $_POST["email"];
        $ct = $_POST["content"];
        mysqli_query($db, "INSERT INTO content (name, email, content) ".
                "VALUE ('$ne', '$em', '$ct')");
    }
    $result = mysqli_query($db, "SELECT * FROM content");
} else {
    echo "Error connecting database.<br/>";
}
?>
<h1>PHP留言板</h1>
<p>
<table>
    <tr>
        <td>姓名</td>
        <td>邮箱</td>
        <td>留言内容</td>
    </tr>
    <?php while ($entry = $result->fetch_object()): ?>
    <tr>
        <td><?php echo $entry->name  ?></td>
        <td><?php echo $entry->email ?></td>
        <td><?php echo $entry->content ?></td>
    </tr>
    <?php endwhile;?>
</table>
<form method="post" action="test.php">
<table>
    <tr>
        <td>姓名</td>
        <td><input name="name" type="text" /></td>
        <td>Email</td>
        <td><input name="email" type="text" /></td>
    </tr>
</table>
<p>
<textarea name="content" rows="10" cols="60"></textarea>
</p>
<button name="submit">提交</button>
</form>
</p>
</body>
</html>